package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class DclrVarInitProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static DclrVarInitProduction instance = new DclrVarInitProduction();

    public static DclrVarInitProduction getInstance() {
        return instance;
    }

    /**
     * Regra: dclr_var_init : dclr_var ('=' inits)?;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!DclrVarProduction.getInstance().analyze(st, et)) {
            return false;
        }

        if (basicParse(st, TokenClass.OPERATOR_ASSIGNMENT)) {
            if (!InitsProduction.getInstance().analyze(st, et)) {
                return skipUntilSynchronize(st, et, "Inicialização incompleta");
            }
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        //from DeclrVar
        first.add(TokenClass.IDENTIFIER);
        first.add(TokenClass.KEYWORD_INTEIRO);
        first.add(TokenClass.KEYWORD_REAL);
        first.add(TokenClass.KEYWORD_LOGICO);
        first.add(TokenClass.KEYWORD_CARACTERE);
        first.add(TokenClass.KEYWORD_STRING);
    }

    @Override
    protected void populateFollow() {
        follow.add(TokenClass.DELIMITER_COMMA);

        //from Variaveis
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        
    }

}
